home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / Inspector / Sources / Document.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  3.6 KB  |  154 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Document.cp
  3.  
  4.     Contains:    TDocument implementation.
  5.  
  6.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #ifndef __WINDOWS__
  11. #include <Windows.h>
  12. #endif
  13.  
  14. #ifndef __DOCUMENT__
  15. #include "Document.h"
  16. #endif
  17.  
  18. /**********************************************************************
  19. **  TDocument
  20. ***********************************************************************/
  21.  
  22. TDocument::TDocument()
  23. {
  24.     fDocWindow = NULL;
  25.     fDocList = NULL;
  26. }
  27.  
  28. TDocument::TDocument(short resID)
  29. {
  30.     InitDocument(resID);
  31. }
  32.  
  33. TDocument::~TDocument(void)
  34. {
  35.     if (fDocList)
  36.         fDocList->RemoveDoc(this);
  37.     DisposeWindow(fDocWindow);
  38. }
  39.  
  40. void TDocument::InitDocument(short resID)
  41. {
  42.     long savedRefNum;
  43.     GetLocalLibraryFile()->Preflight(savedRefNum);
  44.     fDocWindow = GetNewWindow(resID,NULL,(WindowPtr) -1);
  45.     #if qDebug
  46.         if (!fDocWindow)
  47.             DebugStr((ConstStr255Param)"\pTDocument::InitDocument could not GetNewWindow\n");
  48.     #endif
  49.     GetLocalLibraryFile()->Postflight(savedRefNum);
  50.     
  51.     if (fDocWindow)
  52.         SetPort(fDocWindow);
  53.     fDocList = NULL;
  54. }
  55.  
  56. void TDocument::DoZoom(short) {};
  57. void TDocument::DoGrow(EventRecord*) {};
  58. void TDocument::DoContent(EventRecord*) {};
  59. void TDocument::DoKeyDown(EventRecord*) {};
  60. void TDocument::DoActivate(Boolean) {};
  61. void TDocument::DoUpdate() {};
  62. void TDocument::DoOpen() {};
  63. void TDocument::DoClose() { delete this; };// by default, we just delete ourself & let destructor do cleanup
  64. void TDocument::DoSave() {};
  65. void TDocument::DoSaveAs() {};
  66. void TDocument::DoRevert() {};
  67. void TDocument::DoPrint() {};
  68. void TDocument::DoUndo() {};
  69. void TDocument::DoCut() {};
  70. void TDocument::DoCopy() {};
  71. void TDocument::DoPaste() {};
  72. void TDocument::DoClear() {};
  73. void TDocument::DoSelectAll() {};
  74. void TDocument::DoIdle() {};
  75. unsigned long TDocument::CalcIdle() { return kMaxSleepTime; };    // by default, we don't need idle
  76. void TDocument::AdjustCursor(Point) {};            // where is in local coords
  77. Boolean TDocument::HaveUndo() { return false; };
  78. Boolean TDocument::HaveSelection() { return false; };
  79. Boolean TDocument::HavePaste() { return false; };
  80. Boolean TDocument::CanClose() { return true; };
  81. Boolean TDocument::CanSave() { return false; };
  82. Boolean TDocument::CanSaveAs() { return true; };
  83. Boolean TDocument::CanRevert() { return false; };
  84. Boolean TDocument::CanPrint() { return false; };
  85.  
  86. /**********************************************************************
  87. **  TDocumentList
  88. ***********************************************************************/
  89.  
  90. TDocumentList::TDocumentList()
  91. {
  92.     fDocList = NULL;
  93.     fNumDocs = 0;
  94. }
  95.  
  96. TDocumentList::~TDocumentList()
  97. {
  98.     /* destroy all our documents */
  99.     
  100.     while (fDocList) {
  101.         TDocument *theDoc = fDocList->GetDoc();
  102.         RemoveDoc(theDoc);
  103.         theDoc->DoClose();
  104.     }
  105. }
  106.  
  107. // find the TDocument associated with the window
  108. TDocument* TDocumentList::FindDoc(WindowPtr window)
  109. {
  110.     TDocumentLink* temp;
  111.     TDocument* tDoc;
  112.  
  113.     for (temp = fDocList; temp != NULL; temp = temp->GetNext())
  114.       {
  115.         tDoc = temp->GetDoc();
  116.         if (tDoc->GetDocWindow() == window)
  117.           return tDoc;
  118.       }
  119.     return NULL;
  120. }
  121.  
  122. // private list management routines
  123. void TDocumentList::AddDoc(TDocument* doc)
  124. {
  125.     TDocumentLink* temp;
  126.  
  127.     temp = new TDocumentLink(fDocList,doc);
  128.     fDocList = temp;
  129.     doc->SetDocList(this);
  130.     fNumDocs++;
  131. }
  132.  
  133. void TDocumentList::RemoveDoc(TDocument* doc)
  134. {
  135.     TDocumentLink* temp;
  136.     TDocumentLink* last;
  137.  
  138.     last = NULL;
  139.     for (temp = fDocList; temp != NULL; temp = temp->GetNext()) {
  140.         if (temp->GetDoc() == doc) 
  141.         {
  142.             if (last == NULL)                // if first item in list, just set first
  143.                 fDocList = temp->GetNext();
  144.             else 
  145.                 last->SetNext(temp->GetNext());
  146.             delete temp;
  147.             fNumDocs--;
  148.             doc->SetDocList(NULL);
  149.             return;
  150.         }
  151.         else last = temp;
  152.     }
  153. }
  154.